package game;

import java.awt.*;
import java.awt.image.BufferedImage;

public abstract class Sprite {
    public BufferedImage offscreenImage;
    public Graphics2D offscreenGraphics;
    protected BufferedImage image;
    protected int x;
    protected int y;
    protected int height;

    protected int width;
    protected int speed;

    public Sprite(){
        this.init();
    }

    public abstract void init();//初始化
    public void draw(Graphics g){
        g.drawImage(image,x,y,width,height,null);
    }//绘画
    public void drawBounds(Graphics g){
        if(GameData.isBOX){
            g.drawImage(image,x,y,width,height,null);
            Rectangle rectangle = this.getBounds();
            g.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
        }
    }//画出图片所占的矩形大小
    public Rectangle getBounds(){
        return new Rectangle(x,y,width,height);
    }//返回矩形大小
    public boolean impackCheck(Sprite sprite){
        return this.getBounds().intersects(sprite.getBounds());
    }//碰撞检测
    public abstract void move();//移动
    public abstract void destroy();//销毁




}
